<template>
    <div>
        <el-menu
                style="width: 200px; min-height: calc(100vh - 50px)"
                :default-active="this.path"
                router
                class="el-menu-vertical-demo"
        >
            <el-sub-menu index="1" v-if="user.role === 1" >
                <template #title><el-icon><Edit /></el-icon>系统管理</template>
                <el-menu-item index="/user"><el-icon><User /></el-icon>用户管理</el-menu-item>
            </el-sub-menu>
          <el-menu-item index="/book"><el-icon><Notebook /></el-icon>书籍管理</el-menu-item>
          <el-menu-item index="/news"><el-icon><Notebook /></el-icon>新闻管理</el-menu-item>
        </el-menu>
    </div>
</template>


<script>
    import {Edit,Location,Notebook,User,Document,Menu as IconMenu,Setting,} from '@element-plus/icons'
    import request from "../utils/request";
    export default {
      name: "Aside",
      data() {
          return {
              user: {},
              path: this.$route.path,
          }
      },
      components: {Edit,User,Notebook,Location,Document,Setting,IconMenu,},

      //缓存中判断不安全
      created() {
            let userStr = sessionStorage.getItem("user") || "{}";
            this.user = JSON.parse(userStr);
            request.get("/user/"+this.user.id).then(res => {
                if (this.user.code === "0"){
                    this.user = res.data;
                }
            })
      }
    }

</script>

<style scoped>

</style>